#ifndef _SERVER_H_
#define _SERVER_H_

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

class server {
private:
  int s_sock;
  int epoll_fd;
  int res, res_fd;

  static const int MAX_CLIENTS = 10;
  int client_count;

  int listen_port;
  string listen_address;

  struct sockaddr_in server_addr;
  struct sockaddr_in client_addr;
  struct epoll_event ev;
  struct epoll_event events[MAX_CLIENTS];
  int clients[10];

  string r_data;
  void epoll_init();
  void add_sock_to_epoll(int sock);

  void remove_sock(int sock);
  int get_sock_fd();
  void handle_data(int sock);
  void send_data(int client, char const* data);
  void event_loop();

public:

  server(int port = 51025, const char* address = "127.0.0.1");
  ~server();


};

#endif

